package showapi

import (
	"fmt"
)

type (
	Content struct {
		Id    string `json:"id"`
		Title string `json:"title"`
		Text  string `json:"text"`
		Type  int    `json:"type"`
		Ct    string `json:"ct"`
	}

	Body struct {
		AllPages    int       `json:"allPages"`
		Contentlist []Content `json:"contentlist"`
	}

	TextJoke struct {
		Showapi_res_error string `json:"showapi_res_error"`
		Showapi_res_id    string `json:"showapi_res_id"`
		Showapi_res_code  int    `json:"showapi_res_code"`
		Showapi_res_body  Body   `json:"showapi_res_body"`
	}
)

func GetTextJoke(page, maxResult int) (*TextJoke, error) {
	appParams := make(map[string]string)
	appParams["page"] = fmt.Sprintf("%d", page)
	appParams["maxResult"] = fmt.Sprintf("%d", maxResult)

	api := New("21b693f98bd64e71a9bdbb5f7c76659c", "http://route.showapi.com/341-1", "17262")
	jsonResult := TextJoke{}
	err := api.GetJson(appParams, &jsonResult)
	return &jsonResult, err
}
